import axios from 'axios'

let url = 'http://localhost:3000'

// 查找数据
export const getAll = async (keyword) => {
    let data;
    if(keyword){
        data = await axios.get(`${url}/book?keyword=${keyword}`)
    }else{
        data = await axios.get(`${url}/book`)
    }
    return data.data
}

// 查找单个数据
export const getById = async (id) => {
    let data = await axios.get(`${url}/book/${id}`)
    return data.data
}

// 删除数据
export const delItem = async (id) => {
    let data = await axios.delete(`${url}/book/${id}`)
    return data.data
}

// 新增数据
export const addItem = async (obj) => {
    let data = await axios.post(`${url}/book`,obj)
    return data.data
}

// 编辑数据
export const editItem = async (id,obj) => {
    let data = await axios.put(`${url}/book/${id}`,obj)
    return data.data
}